#! /bin/sh
# /etc/rc.d/rc.inet1
# This script is used to bring up the various network interfaces.
#
# Modified for SLAX by Tomas M. <http://www.slax.org/>
#

if [ "$1" = "start" -o "$1" = "" ]; then

   ifconfig lo down 2>/dev/null
   /sbin/ifconfig lo 127.0.0.1 2>/dev/null
   /sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo 2>/dev/null

   # here is how to setup winfi device easily.
   # First type 'iwconfig' command to see which devices are WIFI-enabled
   #
       # find out which device is WIFI-enabled
       #   eth=$(iwconfig 2>&1 | grep IEEE | cut -d " " -f 1)
       #   ifconfig $eth down

       # mac address of your access point
       #   iwconfig $eth ap 11:23:b5:13:43:16

       # channel value. You may skip this one, but some drives require this
       #   iwconfig $eth channel 11 

       # security key for WEP, if you are using it
       #   iwconfig $eth key a43b436a3c6236b4a3c5d2b5a3 

       # your network name
       #   iwconfig $eth essid my_network

       # now enable the device so dhcpcd can see it in the next step
       #   ifconfig $eth up
   #
   # end of wifi sample configuration

   for eth in $(ls /sys/class/net | grep -v sit); do
      # bring all interfaces up and start dhcpcd for all of them
      # use -t 0 to keep it running indefinitely
      if [ "$eth" != "lo" ]; then
         echo "Auto Configure IP address for $eth: /sbin/dhcpcd -t 60 $eth &"
         kill $(cat /etc/dhcpc/dhcpcd-$eth.pid 2>/dev/null) 2>/dev/null
         rm -f /etc/dhcpc/dhcpcd-$eth.pid
         /sbin/ifconfig $eth up 2>/dev/null
         /sbin/dhcpcd -t 0 $eth >/dev/null 2>&1 &
      fi
   done

fi

if [ "$1" = "stop" ]; then
   killall dhcpcd
fi
